Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
The has-ansi npm package is used to check if a string contains ANSI escape codes. These codes are often used to format output in terminal applications, such as changing colors, styles, or other text attributes. This package provides a simple way to detect the presence of these codes in a given string.
Check for ANSI escape codes in a string
This feature allows you to check if a string contains ANSI escape codes. The function `hasAnsi` returns `true` if the string contains any ANSI escape codes, and `false` otherwise. This is useful for determining whether text formatting needs to be stripped or processed differently.
"const hasAnsi = require('has-ansi');\nconsole.log(hasAnsi('\u001B[4mUnicorn\u001B[0m')); // true\nconsole.log(hasAnsi('Unicorn')); // false"
Chalk is a popular npm package for styling terminal text. Unlike has-ansi, which is used to detect ANSI codes, Chalk is used to apply styles such as color, background color, and text formatting (bold, italic) through chainable methods. Chalk focuses on creating styled text, while has-ansi is about detection.
Strip-ansi is a package that removes ANSI escape codes from a string. It complements has-ansi by providing the functionality to clean a string of any ANSI codes that has-ansi can detect. While has-ansi checks for the presence of ANSI codes, strip-ansi is used to remove them.
Ansi-regex is a package that provides a regular expression to match ANSI escape codes. It can be used for a similar purpose as has-ansi, but with a more manual approach, giving developers the flexibility to use the regex in various contexts. Has-ansi offers a simpler and more direct API for detection.
Check if a string has ANSI escape codes
$ npm install has-ansi
const hasAnsi = require('has-ansi');
hasAnsi('\u001B[4mUnicorn\u001B[0m');
//=> true
hasAnsi('cake');
//=> false
FAQs
Check if a string has ANSI escape codes
The npm package has-ansi receives a total of 10,203,891 weekly downloads. As such, has-ansi popularity was classified as popular.
We found that has-ansi demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.